package org.example.dyscript.dynamicscript;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;

import java.util.Map;

public class GroovyScriptRule implements Rule {

  String executeScript = "ali_score > 100 "
      + "&& wx_score < 450 "
      + "&& !pd_living_province.contains(\"乌克兰\") "
      + "&& pd_census_province.contains(\"吉尔吉斯斯坦\")";

  String evaluateScript = "age > 18 && vip.contains(\"vip\")";

  @Override
  public boolean execute(Map<String, Object> parameters) {
    Binding binding = new Binding(parameters);
    GroovyShell shell = new GroovyShell(binding);
    return (boolean) shell.evaluate(executeScript);
  }

  @Override
  public boolean evaluate(Map<String, Object> parameters) {
    Binding binding = new Binding(parameters);
    GroovyShell shell = new GroovyShell(binding);
    return (boolean) shell.evaluate(evaluateScript);
  }
}
